/**
 * 冒泡排序
 */
#include <iostream>
#include <vector>

using namespace std;

void bubbleSort(vector<int> &v)
{
    int n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        bool bCompare = false;  // 判断优化
        for (int j = 0; j < n - i - 1; ++j)
        {
            if (v[j] > v[j + 1])
            {
                std::swap(v[j], v[j + 1]);
                bCompare = true;
            }
        }
        if (!bCompare) 
        {
            break;
        }
    }
}

void printResult(vector<int> &v)  
{
    for (const auto &n : v) {
        cout << n << " ";
    }
    cout << endl;
}

int main()
{
    vector<int> vTest = {1, 3, 45, 7, 2, 7, 3, 76};
    printResult(vTest);
    bubbleSort(vTest);
    printResult(vTest);

    return 0;
}
